﻿if (typeof Phule == "undefined") Phule = {};
if (typeof Phule.Web == "undefined") Phule.Web = {};
Phule.Web.wineknowledge = {
    Init: function () {
        this.Paging.Init();
    },
    Paging: {
        isFirstPaging: true,
        Init: function () {
            var thisObj = this;
            thisObj.GetData(1, true);
        },
        GetData: function (pPageNumber, bmn) {
            var objThis = this;
            var catID = 145;
            var rPerPage = 4;
            if (typeof RowPerPage != 'undefined')
                rPerPage = RowPerPage;

            var data = '{' + $.string.Format('"page":{0},"rows":{1},"catID":"{2}"', pPageNumber, rPerPage, catID) + '}';
            var url = 'Services/NewsService.asmx/GetListNews';

            $.Ajax({
                type: "POST",
                url: url,
                cache: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: data,
                success: function (pData) {
                    var data = eval("(" + pData.d + ")");
                    Phule.Web.wineknowledge.ShowNewsList(data);
                  
                    if (data.records == undefined)
                        data.records = rPerPage;
                    // console.log(data, 'data.total', data.total, 'data.records', data.records);
                    if (bmn) {
                        $("#paging").jpaging({
                            all_items_num: data.total,
                            items_on_page: data.records,
                            callback: function (a, b, c) {
                                objThis.GetData(a);
                            }
                        });
                    }

                }
            });
        }
    },

    ShowNewsList: function (data) {
        var htmlContent = "";
        var pattern = "<li>"
						+'<img src="{0}" />'
						+'<h2 class="title"><a href="{3}">{1}</a></h2>'
						+'<p>{2}</p>'
						+ '<a href="{3}" class="readmore">Chi tiết »</a>'
        + "</li>";
        $.each(data.list, function (index, Item) {
            htmlContent += $.string.Format(pattern, Item.ThumbnailImage, Item.Title, Item.Summary, BuildUrlFriendly("newsdetail", Item.ID, Item.Title));
        });
        $("#news_list_content").html(htmlContent);
    }
}
$(function () {
    Phule.Web.wineknowledge.Init();
});